﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FurnitureSystem
{
    public partial class frmLogin : Form
    {
        public static string depart;
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection conn = connect.Getconect();
            conn.Open();
            string sql = "select * from EmployeeDetail where staffname='"+txtUser.Text+"' and Password='"+txtPass.Text+"' ";
            SqlCommand cmd = new SqlCommand(sql,conn);
            SqlDataReader sdr =cmd.ExecuteReader();
            if (sdr.Read())
            {
                 depart = sdr.GetString(5);
                if (depart == "admin     ")
                {
                    MessageBox.Show("Chào mừng admin đã đăng nhập thành công");
                    frmQuanLyLoaiSP main = new frmQuanLyLoaiSP();
                    main.Show();
                    this.Hide();
                }
                else {
                    MessageBox.Show("chào mừng " + txtUser.Text + " đã đăng nhập thành công");
                    frmMain main = new frmMain();
                    main.Show();
                    this.Hide();
                }
                

            }
            else

            {
                MessageBox.Show("Lỗi đăng nhập");
            }

            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void label4_Click(object sender, EventArgs e)
        {
            frmRegister frm = new frmRegister();
            frm.Show();
            this.Hide();
        }

    }
}
